# Virtual Router Simulator 
#
# Copyright (C) 2009-2010 VRSim Project
# Author: Choonho Son <choonho@kt.com>
# URL: <http://vrsim.googlecode.com>
# For license information, see LICENSE.TXT
#

import VRSim.Globals as globals
from PyQt4 import QtCore,QtGui
import sys


if sys.platform.startswith("win"):
    DELIMETER = "/"
else:
    DELIMETER = "/"

class Singleton(object):
    _instance = None
    def __new__(cls,  *args,  **kwargs):
        if not cls._instance:
            cls._instance = super(Singleton,  cls).__new__(cls,  *args,  **kwargs)
        return cls._instance
   
def debug(string,  msg=""):
    """ print strings if debugging is true
    """
    if globals.debugLevel >= 2:
        print '*DEBUG (' ,  str(msg),  ") : " ,  str(string)
    
def parsePath(str):
    items = str.split(DELIMETER)
    output = ""
    for item in range(len(items) - 1):
        output = output + items[item] + DELIMETER
    return [output,  items[-1]]
    
def message(string,  what="warning"):
    ret = None
    if what == "warning":
        ret = QtGui.QMessageBox.warning(None,  'Warning', string, QtGui.QMessageBox.Yes)
    elif what == "critical":
        ret = QtGui.QMessageBox.critical(None, 'Critical', string, QtGui.QMessageBox.Yes)
    elif what == "information":
        ret = QtGui.QMessageBox.critical(None, 'Information', string, QtGui.QMessageBox.Yes)
    else:
        ret = QtGui.QMessageBox.question(None, 'Question', string, QtGui.QMessageBox.Yes | QtGui.QMessageBox.Cancel)
    
    # return value
    if ret == QtGui.QMessageBox.Cancel:
        return False
    else:
        return True
        
def translate(context,  text):
    """ internationalize
    """
    return QtGui.QApplication.translate(context,  text,  None,  QtGui.QApplication.UnicodeUTF8)

def splash(msg):
    # TODO: splash
    pic = QtGui.QPixmap(":/symbols/loading_6.png")
    splash = QtGui.QSplashScreen(pic,  QtCore.Qt.WindowStaysOnTopHint)
    splash.showMessage(msg,  QtCore.Qt.AlignBottom | QtCore.Qt.yellow)
    splash.show()
    globals.GApp.processEvents()
    
